<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>数据管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/rightCon.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/page.css}" media="all">
</head>

<body class="layui-layout-body layui-layout-body-scroll">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div class="scroll-box bgWhite box-shadows border-radius4">
        <div class="scroll-box-padding">
            <div class="scroll-box-con">
                <div class="border-bot1px pb10px mb20px">
                    <div class="form-box form-style">
                        <div>
                            <div class="form-title">
                                <label>关键字：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" id="userName" placeholder="请输入">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>设备名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" id="deviceName" placeholder="请输入">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>用户名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="orgId">
                                        <option value="">请选择</option>

                                    </select>
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>下载状态：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="state">
                                        <option value="">请选择</option>
                                        <option value="0">未下载</option>
                                        <option value="1">已下载</option>
                                        <!--<option value="2">下载失败</option>-->
                                    </select>
                                </p>
                            </div>
                        </div>
                        <div class="form-box-btn overflow">
                            <span class="white border-radius4 border-blue blue inline-block pl20px pr20px lh30px cursor" onclick="queryPage();">查&nbsp;询</span>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="mb20px lh32px overflow table-btn-img">
                        <p class="right">共<span class="red" id="total"></span>条数据</p>
                    </div>
                    <div class="border1px border-box border-radius4 layui-table-img">
                        <table class="layui-hide" id="test" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/static/js/jquery-3.1.1.min.js}"></script>
<script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/static/js/selectColor.js}" charset="utf-8"></script>
<script>

    $(function () {
        getOrg();
        var orgId = $("#orgId").val();
        var userName = $("#userName").val();
        var deviceName = $("#deviceName").val();
        var state = $("#state").val();
        getPage(orgId, userName, deviceName, state);
    });

    function queryPage(){
        var orgId = $("#orgId").val();
        var userName = $("#userName").val();
        var deviceName = $("#deviceName").val();
        var state = $("#state").val();
        getPage(orgId, userName, deviceName, state)
    }

    function getPage(orgId, userName, deviceName, state) {
        //左侧菜单栏
        layui.use(['element', 'table'], function () {
            var element = layui.element;
            var table = layui.table;
            var orgId = $("#orgId").val();
            var userName = $("#userName").val();
            var deviceName = $("#deviceName").val();
            var state = $("#state").val();

            table.render({
                elem: '#test',
                url: "../device/getList"
                , where: {
                    deviceName: deviceName, state: state, orgId: orgId, userName:userName
                },
                id: 'idTest'
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    ,limitName: 'nums' //每页数据量的参数名，默认：limit
                },
                page: true //开启分页
                , limit: 10 //每页显示的条数
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.info(res);
                    $("#total").html(res.count);
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.count,
                        "data": res.data,
                    };
                },
                cols: [
                    [ //表头
                        {
                            title: '序号',
                            fixed: 'left',
                            type: 'numbers',
                            width: 70,
                        }, {
                            field: 'orgName',
                            title: '用户名称',
                        }, {
                            field: 'userName',
                            title: '姓名',
                        }, {
                            field: 'sex',
                            title: '性别',
                            templet: function (res) {
                                if(res.sex == 1){
                                    return "<div class='table-list-btn'><span>男</span></div>"
                                } else if(res.sex == 2){
                                    return "<div class='table-list-btn'><span>女</span></div>"
                                }
                            }
                        }, {
                            field: 'mobile',
                            title: '手机号',
                        }, {
                            field: 'photo',
                            title: '照片',
                            templet: function (res) {
                                if(res.photo != null && res.photo != ''){
                                    return "<div class='table-img'><span><img src='"+res.photo+"'></span></div>"
                                } else if(res.sex == 2){
                                    return "<div class='table-img'><span><img src='"+res.photo+"'></span></div>"
                                }

                            }
                        }, {
                            field: 'deviceName',
                            title: '设备名称',
                        }, {
                            field: 'isIssued',
                            title: '下载状态',
                            width: 160,
                            fixed: 'right',
                            templet: function (res) {
                                if(res.isIssued == 0){
                                    return "<div class='table-list-btn'><span>未下载</span></div>"
                                } else if(res.isIssued == 1){
                                    return "<div class='table-list-btn'><span>已下载</span></div>"
                                }
                            }
                        }
                    ]
                ], done: function (res, curr, count) {
                    $("#count").text(count);
                    currentPage = curr;
                }
            });
        });
    }

    function getOrg(){
        var orgId = $("#orgId").val();
        $.ajax({
            url: "../device/getOrgList",
            type: "post",
            async: false,
            dataType: "json",
            data: {"id": orgId},
            success: function (result) {
                console.info(result);
                var html = "<option value=''>请选择</option>";
                if (result.code == 200) {
                    $.each(result.list,function (key,value) {
                        html += "<option value='"+value.id+"'>"+value.orgName+"</option>";
                    })
                    $("#orgId").html(html);
                } else {
                    layer.msg(result.msg);
                }
            }
        })
    }




</script>
</body>

</html>
